#ifndef TOKZRGENTR_UTILS_UTILS_H
#define TOKZRGENTR_UTILS_UTILS_H

#include"u16string_ref.h"
#include<string>
#include<codecvt>
//#	helper function to help to analyze the tok


namespace TokzrGentr {
	inline size_t to_num(const u16string_ref &ref)
	{
		size_t bit_count = 0;
		size_t scale = 10;
		size_t val = 0;
		while (bit_count < ref.length())
		{
			auto ch = ref[bit_count];
			size_t num = ch - u'0';
			val = (val * scale) + num;
			bit_count++;
		}
		return val;
	}

	//#	helper function for some converting.

	std::u16string utf8_to_utf16_vs1900l(const std::string &utf8_str)
	{
		std::wstring_convert<std::codecvt_utf8<int16_t>, int16_t> convert;
		auto asInt = convert.from_bytes(utf8_str);
		return std::u16string(reinterpret_cast<char16_t const *>(asInt.data()), asInt.length());
	}

	std::string utf16_to_utf8(const u16string &utf16_str)
	{
		std::wstring_convert<std::codecvt_utf8_utf16<int16_t>, int16_t> convert;
		auto p = reinterpret_cast<const int16_t *>(utf16_str.data());
		return convert.to_bytes(p, p + utf16_str.size());
	}

	/*
	std::u16string utf8_to_utf16_vs1900g(const std::string &utf8_str)
	{
		std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
		return convert.from_bytes(utf8_str);
	}
	*/
	std::u16string utf8_to_utf16(const std::string &utf8_str)
	{
		return utf8_to_utf16_vs1900l(utf8_str);
	}
};
#endif // !TOKZRGENTR_UTILS_UTILS_H
